<?php

namespace app\index\model;

use think\Model;

class Comments extends Model
{
    protected $table='comments';

    public function goods(){
        return $this->belongsTo('Goods','goods_id','id');
    }

    public function user(){
        return $this->belongsTo('User','user_id','id');
    }
    /**
     * 获取评论数
     * @param $goods_id
     * @return int|string
     */
    public function getCommentCount($goods_id){
        $count=$this->where('goods_id',$goods_id)
            ->count();
        return $count;
    }

    /**
     * 获取评论
     * @param $goods_id
     * @return \think\Paginator
     */
    public function getComment($goods_id){
        $result=$this->where('goods_id',$goods_id)
            ->with('user')
            ->paginate(3);
        return $result;
    }
}
